package com.ruoyi.project.jiaqin.advertcooperate.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.advertcooperate.domain.JiaqinAdvertCooperate;
import com.ruoyi.project.jiaqin.advertcooperate.service.IJiaqinAdvertCooperateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告合作类型Controller
 * 
 * @author LCL
 * @date 2021-10-27
 */
@Controller
@RequestMapping("/jiaqin/advertcooperate")
public class JiaqinAdvertCooperateController extends BaseController
{
    private String prefix = "jiaqin/advertcooperate";

    @Autowired
    private IJiaqinAdvertCooperateService jiaqinAdvertCooperateService;

    @RequiresPermissions("jiaqin:advertcooperate:view")
    @GetMapping()
    public String advertcooperate()
    {
        return prefix + "/advertcooperate";
    }

    /**
     * 查询广告合作类型列表
     */
    @RequiresPermissions("jiaqin:advertcooperate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinAdvertCooperate jiaqinAdvertCooperate)
    {
        startPage();
        List<JiaqinAdvertCooperate> list = jiaqinAdvertCooperateService.selectJiaqinAdvertCooperateList(jiaqinAdvertCooperate);
        return getDataTable(list);
    }

    /**
     * 导出广告合作类型列表
     */
    @RequiresPermissions("jiaqin:advertcooperate:export")
    @Log(title = "广告合作类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinAdvertCooperate jiaqinAdvertCooperate)
    {
        List<JiaqinAdvertCooperate> list = jiaqinAdvertCooperateService.selectJiaqinAdvertCooperateList(jiaqinAdvertCooperate);
        ExcelUtil<JiaqinAdvertCooperate> util = new ExcelUtil<JiaqinAdvertCooperate>(JiaqinAdvertCooperate.class);
        return util.exportExcel(list, "advertcooperate");
    }

    /**
     * 新增广告合作类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告合作类型
     */
    @RequiresPermissions("jiaqin:advertcooperate:add")
    @Log(title = "广告合作类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinAdvertCooperate jiaqinAdvertCooperate)
    {
        return toAjax(jiaqinAdvertCooperateService.insertJiaqinAdvertCooperate(jiaqinAdvertCooperate));
    }

    /**
     * 修改广告合作类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinAdvertCooperate jiaqinAdvertCooperate = jiaqinAdvertCooperateService.selectJiaqinAdvertCooperateById(id);
        mmap.put("jiaqinAdvertCooperate", jiaqinAdvertCooperate);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告合作类型
     */
    @RequiresPermissions("jiaqin:advertcooperate:edit")
    @Log(title = "广告合作类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinAdvertCooperate jiaqinAdvertCooperate)
    {
        return toAjax(jiaqinAdvertCooperateService.updateJiaqinAdvertCooperate(jiaqinAdvertCooperate));
    }

    /**
     * 删除广告合作类型
     */
    @RequiresPermissions("jiaqin:advertcooperate:remove")
    @Log(title = "广告合作类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinAdvertCooperateService.deleteJiaqinAdvertCooperateByIds(ids));
    }
}
